<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>27_关于this指向的面试题</title>
</head>

<body>
    <script>
        var name = "window 全局变量";
        var obj = {
            name: "对象属性",
            sayName: function () {
                console.log(this.name);
            },
            inner: {
                name: "内部对象属性",
                sayName: function () {
                    console.log(this.name);
                }
            }
        };

        var otherFn = obj.sayName;

        // 分别写出以下调用的输出结果
        obj.sayName();  // 对象属性
        otherFn(); // window 全局变量
        obj.inner.sayName();  // 内部对象属性
    </script>
</body>

</html>